/*
 * @Description: 话题数据模型
 * @Author: iamsmiling
 * @Date: 2021-05-23 16:09:40
 * @LastEditTime: 2021-06-11 12:11:58
 */

import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/common_kit/color_kit.dart';
import 'package:flutter/material.dart';

enum VipLevel { m, q, y }

extension VipLevelKit on VipLevel {
  String get icon =>
      {
        VipLevel.m: R.image.mVIP,
        VipLevel.q: R.image.qVIP,
        VipLevel.y: R.image.yVIP
      }[this] ??
      "";
}

class TopicTagEntity {
  late Color color;
  late String text;

  TopicTagEntity.fromJson(Map json) {
    text = json["text"];
    color = ColorKit.fromHex(json["color"]);
  }

  TopicTagEntity({required this.color, required this.text});
}

class TopicEntity {
  late String userAvatar;
  late String nickname;

  ///职位级别
  late String position;

  late int vipCode;

  late List<TopicTagEntity> tags;

  late int viewCount;
  late int transactionCount;

  late String title;
  late Color titleColor;

  late Color bannerColor;

  late String bannerLabel;

  late bool contacted;

  late bool browsed;

  VipLevel get vipLevel =>
      {
        1: VipLevel.m,
      }[vipCode] ??
      VipLevel.m;

  TopicEntity.fromJson(Map json) {
    json = {
      "avatar":
          "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=374502093,533018727&fm=26&gp=0.jpg",
      "nickname": "不会游泳的鱼",
      "position": "总经理",
      "vip_code": 1,
      "banner_label": "头条",
      "banner_color": "FD8B05",
      "title": "【货拉拉】趣看资讯，多种广告业务，寻优质渠道， 欢迎大佬来聊！",
      "title_color": "FF4800",
      "contacted": true,
      "browsed": true,
      "view_count": 365,
      "transaction_count": 72,
      "tags": [
        {"text": "广告主", "color": "DCF9F0"},
        {"text": "异业合作", "color": "E3F6FD"},
        {"text": "渠道主", "color": "E3F6FD"}
      ]
    };
    userAvatar = json["avatar"];
    nickname = json["nickname"];
    position = json["position"];
    vipCode = json["vip_code"];
    bannerLabel = json["banner_label"];
    bannerColor = ColorKit.fromHex(json["banner_color"]);
    title = json["title"];
    titleColor = ColorKit.fromHex(json["title_color"]);
    contacted = json["contacted"];
    browsed = json["browsed"];
    tags = json["tags"]
        .map((e) => TopicTagEntity.fromJson(e))
        .cast<TopicTagEntity>()
        .toList();
    viewCount = json["view_count"];
    transactionCount = json["transaction_count"];
  }

//  VipLevel get vipLevel{

//  }
}

var map = {
  "code": 0,
  "data": [
    {
      "avatar":
          "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=374502093,533018727&fm=26&gp=0.jpg",
      "nickname": "不会游泳的鱼",
      "position": "总经理",
      "vip_code": 1,
      "banner_label": "头条",
      "banner_color": "FD8B05",
      "title": "【货拉拉】趣看资讯，多种广告业务，寻优质渠道， 欢迎大佬来聊！",
      "title_color": "FF4800",
      "contacted": true,
      "browsed": true,
      "view_count": 365,
      "transaction_count": 72,
      "tags": [
        {"text": "广告主", "color": "DCF9F0"},
        {"text": "资源置换", "color": "#555555"},
        {"text": "异业合作", "color": "E3F6FD"},
        {"text": "渠道主", "color": "E3F6FD"}
      ]
    }
  ],
  "message": ""
};
